package com.barbeque.mall.controller;

import com.barbeque.mall.bean.BaseRespVo;
import com.barbeque.mall.bean.BaseRespVoNoData;
import com.barbeque.mall.bean.config.ExpressConfigVo;
import com.barbeque.mall.bean.config.MallConfigVo;
import com.barbeque.mall.bean.config.OrderConfigVo;
import com.barbeque.mall.bean.config.WxConfigVo;
import com.barbeque.mall.service.ConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Tezel
 * @since 2022/07/18 09:30
 */

@RestController
@RequestMapping("admin/config")
public class AdminConfigController {

    @Autowired
    ConfigService configService;

    @RequiresPermissions("admin:config:mall")
    @RequestMapping(value = "mall",method = RequestMethod.GET)
    public BaseRespVo listMall(){

        MallConfigVo mallConfigVo = configService.mall();

        return BaseRespVo.ok(mallConfigVo);
    }

    @RequiresPermissions("admin:config:mall")
    @RequestMapping(value = "mall",method = RequestMethod.POST)
    public BaseRespVoNoData updateMall(@RequestBody MallConfigVo mallConfig){

        configService.updateMall(mallConfig);

        return BaseRespVoNoData.ok();
    }


    @RequiresPermissions("admin:config:express")
    @RequestMapping(value = "express",method = RequestMethod.GET)
    public BaseRespVo express(){

        ExpressConfigVo expressConfigVo = configService.express();

        return BaseRespVo.ok(expressConfigVo);
    }

    @RequiresPermissions("admin:config:express")
    @RequestMapping(value = "express",method = RequestMethod.POST)
    public BaseRespVoNoData updateExpress(@RequestBody ExpressConfigVo expressConfigVo){

        configService.updateExpress(expressConfigVo);

        return BaseRespVoNoData.ok();
    }




    @RequiresPermissions("admin:config:order")
    @RequestMapping(value = "order",method = RequestMethod.GET)
    public BaseRespVo order(){

        OrderConfigVo orderConfigVo = configService.order();

        return BaseRespVo.ok(orderConfigVo);
    }

    @RequiresPermissions("admin:config:order")
    @RequestMapping(value = "order",method = RequestMethod.POST)
    public BaseRespVoNoData orderExpress(@RequestBody OrderConfigVo orderConfigVo){

        configService.updateOrder(orderConfigVo);

        return BaseRespVoNoData.ok();
    }


    @RequiresPermissions("admin:config:wx")
    @RequestMapping(value = "wx",method = RequestMethod.GET)
    public BaseRespVo wx(){

        WxConfigVo wxConfigVo = configService.wx();

        return BaseRespVo.ok(wxConfigVo);
    }

    @RequiresPermissions("admin:config:wx")
    @RequestMapping(value = "wx",method = RequestMethod.POST)
    public BaseRespVoNoData wxExpress(@RequestBody WxConfigVo wxConfigVo){

        configService.updateWx(wxConfigVo);

        return BaseRespVoNoData.ok();
    }
}
